from django.contrib.staticfiles.storage import staticfiles_storage
from django.urls import reverse
from jinja2 import Environment


# def jinja2_env(**options):
#     env = Environment(**options)
#     env.globals.update(
#         {
#             "static": staticfiles_storage.url,
#             "url": reverse # 使用django的 reverse 函数替换 url 函数 反向解析
#         }
#     )
#
#     return env


def jinja2_environment(**options):
    env = Environment(**options)
    env.globals.update({
        'static': staticfiles_storage.url,
        'url': reverse,
    })
    return env